#!/usr/bin/env node

/**
 * Request模式预约测试脚本
 * 
 * 使用方法：
 *   node scripts/test-request-booking.mjs          # 单个预约测试
 *   node scripts/test-request-booking.mjs [count]  # 多个预约测试
 */

import { spawn } from 'node:child_process'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
const projectRoot = join(__dirname, '..')
const testFile = join(projectRoot, 'scripts', 'test-request-booking.ts')

const args = process.argv.slice(2)
const count = args[0] || '1'

console.log('Request模式预约测试')
console.log('='.repeat(60))
console.log(`预约数量: ${count}`)
console.log('='.repeat(60))
console.log()

const proc = spawn('npx', ['tsx', '--tsconfig', join(projectRoot, 'tsconfig.node.json'), testFile, count], {
  cwd: projectRoot,
  stdio: 'inherit',
  shell: true,
})

proc.on('close', (code) => process.exit(code || 0))
proc.on('error', (error) => {
  console.error('执行失败:', error)
  process.exit(1)
})

